<?php
require_once ROOT_ADMIN_MODELS.DS.'Models_Base.php';
class Model_User extends Models_Base{		    
    public function __construct(){
    	parent::__construct();
       // $this->db=Zend_Registry::get('db');
    }
    public function listUser()
    {
       	 $sql="SELECT user.*, group.name gname 
       	 		FROM 
       	 			`user`,`group` 
				WHERE 
					`user`.group_id=`group`.id
				AND
					`user`.active != -1
				ORDER BY 
					`user`.id ASC
             ";
        $data=$this->_db->fetchAll($sql,null,Zend_Db::FETCH_OBJ);
        return $data;
    }
    
    public function getGroupById($id)
    {
    	$sql="
			SELECT 
				group_id
			FROM 
				user
			WHERE 
				id=$id			
    	";
    	$data=$this->_db->fetchOne($sql,null,Zend_Db::FETCH_OBJ);
    	return $data;
    } 
     
    public function getUserbyID($id)
    {
    	$sql=" 	SELECT
		    		*
		    	FROM
		    		user
		    	WHERE
		    		id=$id
    	";
    	$data=$this->_db->fetchRow($sql,null,Zend_Db::FETCH_OBJ);
    	return $data;
    }
    
    public function update($id,$group)
    {
    	$sql="
    		UPDATE 
    			`user`
    		SET 
    			group_id=$group
    		WHERE 
    		 	id=$id
    	";
    	$this->_db->query($sql);    	    		
    }
    
    public function updateuser($obj)
    {
    	$sql="
		    	UPDATE
		    		`user`
		    	SET
    				group_id=$obj->group_id,
    				phone= '$obj->phone',
    				active=$obj->active,
    				email='$obj->email'
    			WHERE
    				id=$obj->id";
    	$this->_db->query($sql);
    }
    
    public function active($id,$active)
    {
    	$sql="	UPDATE
    				`user`
    			SET
    				active=$active
    			WHERE
    				id=$id";
    	$this->_db->query($sql);
    }
    public function getpass($id)
    {
    	$sql=" 	SELECT
		    		passWord
		    	FROM
		    		user
		    	WHERE
		    		id=$id
		    	";
    	$data=$this->_db->fetchOne($sql,null,Zend_Db::FETCH_OBJ);
    	return $data;
    }
    public function setpass($id,$passWord)
    {
    	$sql="	UPDATE
		    		`user`
		    	SET
		    		passWord='$passWord'
		    	WHERE
		    		id=$id";
    	$this->_db->query($sql);
    }
    
}
		